package com.hystericalporpoises.thingamajava;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import org.pojomatic.Pojomatic;
import org.pojomatic.annotations.AutoProperty;

class RelationshipMap extends HashMap<String, String> {

  Set<RelationshipKey> getKeysStartingWith(String prefix) {
    Set<RelationshipKey> prefixedKeys = new HashSet<RelationshipKey>();
    for (String key : keySet()) {
      String fieldPrefix = prefix + ".";
      if (key != null && key.startsWith(fieldPrefix)) {
        prefixedKeys.add(new RelationshipKey().setMapKey(key).setFieldKey(key.substring(fieldPrefix.length())));
      }
    }
    return prefixedKeys;
  }

  @AutoProperty
  static class RelationshipKey {

    private String mapKey;

    public String getMapKey() { return this.mapKey; }
    public RelationshipMap.RelationshipKey setMapKey(String mapKey) { this.mapKey = mapKey; return this; }

    private String fieldKey;

    public String getFieldKey() { return this.fieldKey; }
    public RelationshipMap.RelationshipKey setFieldKey(String fieldKey) { this.fieldKey = fieldKey; return this; }

    @Override
    public boolean equals(Object obj) {
      return Pojomatic.equals(this, obj);
    }

    @Override
    public int hashCode() {
      return Pojomatic.hashCode(this);
    }

    @Override
    public String toString() {
      return Pojomatic.toString(this);
    }

  }


}
